package com.GXKJ.Test.Util;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;
import java.sql.*;

/**
 * @author nongzhiquan
 * @date 2021年05月12日 16:25
 */
@Configuration
@Component
public class DBUtil {

    private static String sql="select * from role";

    @Autowired


    public static void main(String[] args) throws SQLException {
        String url = "jdbc:mysql://127.0.0.1/gx_kj";
        String name = "com.mysql.jdbc.Driver";
        String user = "root";
        String password = "root";
        Connection connection = null;
        PreparedStatement preparedStatement = null;
        ResultSet resultSet = null;

        try{
            //指定连接类型
            Class.forName(name);
            //获取连接
            connection = DriverManager.getConnection(url,user,password);
            //准备执行语句
            preparedStatement = connection.prepareStatement(sql);

            resultSet=preparedStatement.executeQuery();
            while (resultSet.next()) {
                System.out.println(resultSet);
            }
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            connection.close();
            preparedStatement.close();
        }
    }
}
